<?php
/**
 * @author Tongle Xu <xutongle@gmail.com>
 * @copyright Copyright (c) 2003-2103 Jinan TintSoft development co., LTD
 * @license http://www.tintsoft.com/html/about/copyright/
 * @version $Id$
 */
namespace Leaps\Web;

use Leaps\Base\Object;

/**
 * JsExpression marks a string as a JavaScript expression.
 *
 * When using [[Leaps\Stdlib\Json::encode()]] to encode a value, JsonExpression objects
 * will be specially handled and encoded as a JavaScript expression instead of a string.
 *
 * @author Tongle Xu <xutongle@gmail.com>
 * @since 4.0
 */
class JsExpression extends Object
{
	/**
	 * @var string the JavaScript expression represented by this object
	 */
	public $expression;

	/**
	 * Constructor.
	 * @param string $expression the JavaScript expression represented by this object
	 * @param array $config additional configurations for this object
	 */
	public function __construct($expression, $config = [])
	{
		$this->expression = $expression;
		parent::__construct($config);
	}

	/**
	 * The PHP magic function converting an object into a string.
	 * @return string the JavaScript expression.
	 */
	public function __toString()
	{
		return $this->expression;
	}
}
